#ifndef __ONVIF_H
#define __ONVIF_H

//#include "soapH.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <pthread.h>
#include <signal.h>
#include "save_configs.h"

#define DBG(fmt,args...) \
	do{ \
		fprintf(stderr,"%s in %d:",__FUNCTION__,__LINE__); \
		fprintf(stderr,fmt,##args); \
	}while(0)

#define INFO(outfile) fprintf(outfile,"%s in %d.\n",__FUNCTION__,__LINE__)

#define TRUE 1
#define FALSE 0
#define IPv4_LEN  20
#define IPv6_LEN 64 
#define INFO_LEN 64 
#define XADDR_LEN 128
#define UUID_LEN 128 
#define TOKEN_LEN 256

#define CONFIG_NUM  7

typedef enum
{
	IO_CAP_VS = 0,
	IO_CAP_VO,
	IO_CAP_AS,
	IO_CAP_AO,
	IO_CAP_RO,

	IO_CAP_MAX_POS
}IO_CAP_POS;

typedef enum
{
	MAX_PROFILES_NUM = 0,
	RTP_MULTICAST,
	RTP_TCP,
	RTP_RTSP_TCP,
	NON_AGGRE_CONTROL,

	MEDIA_CAP_MAX_POS
}MEDIA_CAP_POS;

typedef enum
{
	EVENT_CAP_SPS = 0,
	EVENT_CAP_PPS,
	EVENT_CAP_PSMIS,

	EVENT_CAP_MAX_POS
}EVENT_CAP_POS;

typedef enum
{
	FAULT_CODE = 0,
	PARENT_SUBCODE,
	FAULT_REASON,
	SPEC_SUBCODE,

	FAULT_END
}FAULT_CODE_POS;

//=====================================//
extern char media_caps[];
extern char deviceio_caps[];
extern char events_caps[];


//=====================================//
//----- some utilities ----------//
char *get_ipaddr(void);
char *get_xaddrs(void);
char *get_uuid(void);
char *cmp_and_cpy(char **dst, const char *src);
int search_matchtoken_pos(char *array[], int size, int elem_num, const char *token, int token_pos);
int process_specific_fault(struct soap *soap, const char *fault_code[]);

//----------------------------------------------------------------------------//
//init and exit configurations getting
int init_mediaservice_configs(void);
int exit_mediaservice_configs(void);
int init_receiverservice_configs(void);
int exit_receiverservice_configs(void);

/* 
 * get service capabilities 
 */
int get_eventservice_cap(struct soap *soap, struct tev__Capabilities *event);
int get_mediaservice_cap(struct soap*soap,struct trt__Capabilities *media);
int get_deviceioservice_cap(struct soap *soap, struct tmd__Capabilities * deviceio);
int get_analyticservice_cap(struct soap *soap, struct tan__Capabilities * analytics);
int get_imageservice_cap(struct soap *soap, struct timg__Capabilities * image);
int get_displayservice_cap(struct soap *soap, struct tls__Capabilities * display);
int get_ptzservice_cap(struct soap *soap, struct tptz__Capabilities * ptz);
int get_recordservice_cap(struct soap *soap, struct trc__Capabilities * record);
int get_replayservice_cap(struct soap *soap, struct trp__Capabilities * replay);
int get_receiverservice_cap(struct soap *soap, struct trv__Capabilities * receiver);
int get_searchservice_cap(struct soap *soap, struct tse__Capabilities * search);


/*
 * get video and audio configurations
 */
int search_vstoken_pos(const char *token);
int search_astoken_pos(const char *token);
int search_votoken_pos(const char *token);
int search_aotoken_pos(const char *token);
int get_videosource_config(struct soap *soap,int id, struct tt__VideoSourceConfiguration *vs_config);
int get_audiosource_config(struct soap *soap,int id,struct tt__AudioSourceConfiguration *as_config);
int get_videoutput_config(struct soap *soap,int id,struct tt__VideoOutputConfiguration *vo_config);
int get_audioutput_config(struct soap *soap,int id,struct tt__AudioOutputConfiguration*ao_config);

/*
 * set video and audio  source/output configurations
 */
int set_videosource_config(int persis_flag, struct tt__VideoSourceConfiguration *pconf);
int set_audiosource_config(int persis_flag, struct tt__AudioSourceConfiguration*pconf);
int set_audioutput_config(int persis_flag, struct tt__AudioOutputConfiguration *pconf);
int set_videoutput_config(int persis_flag, struct tt__VideoOutputConfiguration *pconf);

//-----------------------------
/*
 * get configuration options
 */
int get_voconfig_options(struct soap *soap, const char *token, struct tt__VideoOutputConfigurationOptions*vo_options);
int get_aoconfig_options(struct soap *soap, const char *token,const char *profile_token,struct tt__AudioOutputConfigurationOptions*ao_options);
int get_asconfig_options(struct soap *soap, const char *as_token, const char *profile_token,struct tt__AudioSourceConfigurationOptions*as_options);
int get_vsconfig_options(struct soap *soap, const char *vs_token,const char *profile_token, struct tt__VideoSourceConfigurationOptions*vs_options);
int get_veconfig_options(struct soap *soap, const char *ve_token, const char *profile_token,struct tt__VideoEncoderConfigurationOptions *ve_options);
int get_metaconfig_options(struct soap *soap, const char *meta_token, const char *profile_token,struct tt__MetadataConfigurationOptions *meta_options);

#endif

